// 将多个参数的传入转化成n个函数的操作称为函数柯里化，函数柯里化可以用来暂存变量

function sum(a, b, c, d) {
    return a + b + c + d;
}



// const sum1 = curring(sum)
// console.log(sum1)
// const sum2 = sum1(1)
// const sum3 = sum2(2, 3)
// const result = sum3(4)
// console.log(result)

function curring(fn) {
    const inner = (args = []) => {
        return args.length >= fn.length ? fn(...args) : (...userArgs) => inner([...args, ...userArgs])
    }

    return inner()
}

const result = curring(sum)(1)(2, 3)(4)
console.log(result)



function isType(typing, val) {
    return Object.prototype.toString.call(val) === `[object ${typing}]`
}

const util = {};

['String','Number','Boolean','Null','Undefined'].forEach(type => {
    util['is'+type] = curring(isType)(type)
})
console.log(util.isString(123))
console.log(util.isUndefined(undefined))